package com.atguigu.lease.web.app.custom.config;

import com.atguigu.lease.web.app.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Package: com.atguigu.lease.web.app.custom.config
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/28 14:30
 */
@SpringBootConfiguration
public class WebMvcConfiguration implements WebMvcConfigurer {

    private final AuthenticationInterceptor authenticationInterceptor;
    @Value("${app.auth.path-patterns.include}")
    private String[] includePathPatterns;
    @Value("${app.auth.path-patterns.exclude}")
    private String[] excludePathPatterns;

    public WebMvcConfiguration(AuthenticationInterceptor authenticationInterceptor) {
        this.authenticationInterceptor = authenticationInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.authenticationInterceptor)
                .addPathPatterns(this.includePathPatterns)
                .excludePathPatterns(this.excludePathPatterns);
    }
}